package com.shared.server.impl;

import com.shared.dao.PCouponMapper;
import com.shared.pojo.PCoupon;
import com.shared.server.PCouponServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PCouponServerImpl implements PCouponServer {
    long ren = new Date().getTime();
    long rs = 30 * 24 * 60 * 60;
    long re = rs * 1000;
    long ser = ren + re;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String res = simpleDateFormat.format(ser);

    @Autowired
    private PCouponMapper pCouponMapper;

    @Override
    public List<PCoupon> findByUserid(Integer userid) {
        return pCouponMapper.findByUserid(userid);
    }

    @Override
    public List<PCoupon> findByUserId(Integer userid) {
        return pCouponMapper.findByUserId(userid);
    }

    @Override
    public List<PCoupon> findPcoupon() {
        return pCouponMapper.findPcoupon();
    }

    @Override
    public void deletecoupon(Integer id) {
        this.pCouponMapper.deletecoupon(id);
    }

    @Override
    public void addCoupon1() {
        PCoupon pCoupon = new PCoupon();
        pCoupon.setUserid(1);
        pCoupon.setCname("满100元立减10元");
        pCoupon.setAmount(10);
        pCoupon.setCriteria(100);
        pCoupon.setState(0);
        pCoupon.setStarttime(new Date());
        pCoupon.setEndtime(res);
        this.pCouponMapper.insert(pCoupon);
    }
    @Override
    public void addCoupon2() {
        PCoupon pCoupon = new PCoupon();
        pCoupon.setUserid(1);
        pCoupon.setCname("满300元立减20元");
        pCoupon.setAmount(20);
        pCoupon.setCriteria(300);
        pCoupon.setState(0);
        pCoupon.setStarttime(new Date());
        pCoupon.setEndtime(res);
        this.pCouponMapper.insert(pCoupon);
    }
    @Override
    public void addCoupon3() {
        PCoupon pCoupon = new PCoupon();
        pCoupon.setUserid(1);
        pCoupon.setCname("满500元立减50元");
        pCoupon.setAmount(50);
        pCoupon.setCriteria(500);
        pCoupon.setState(0);
        pCoupon.setStarttime(new Date());
        pCoupon.setEndtime(res);
        this.pCouponMapper.insert(pCoupon);
    }
    @Override
    public void addCoupon4() {
        PCoupon pCoupon = new PCoupon();
        pCoupon.setUserid(1);
        pCoupon.setCname("满1000元立减100元");
        pCoupon.setAmount(100);
        pCoupon.setCriteria(1000);
        pCoupon.setState(0);
        pCoupon.setStarttime(new Date());
        pCoupon.setEndtime(res);
        this.pCouponMapper.insert(pCoupon);
    }


}
